
zxt.ui.TreeConfig = {
	rootIcon        : zxt.cfg.IMAGES_PATH + '/eftree_foldericon.png',
	openRootIcon    : zxt.cfg.IMAGES_PATH + '/eftree_openfoldericon.png',
	folderIcon      : zxt.cfg.IMAGES_PATH + '/eftree_foldericon.png',
	openFolderIcon  : zxt.cfg.IMAGES_PATH + '/eftree_openfoldericon.png',
	fileIcon        : zxt.cfg.IMAGES_PATH + '/eftree_file.png',
	iIcon           : zxt.cfg.IMAGES_PATH + '/eftree_i.png',
	lIcon           : zxt.cfg.IMAGES_PATH + '/eftree_l.png',
	lMinusIcon      : zxt.cfg.IMAGES_PATH + '/eftree_lminus.png',
	lPlusIcon       : zxt.cfg.IMAGES_PATH + '/eftree_lplus.png',
	tIcon           : zxt.cfg.IMAGES_PATH + '/eftree_t.png',
	tMinusIcon      : zxt.cfg.IMAGES_PATH + '/eftree_tminus.png',
	tPlusIcon       : zxt.cfg.IMAGES_PATH + '/eftree_tplus.png',
	blankIcon       : zxt.cfg.IMAGES_PATH + '/eftree_blank.png'
};

/**
 * 
 * <p>树控件,继承自zxt.ui.TreeTemplate</p>
 * @class 
 * @param {zxt.data.TreeModel} sModel 树状数据模型
 * @param {String} sLabel 标签
 * @param {String} sText  描述
 */
zxt.ui.Tree = function( sModel, sLabel, sText ) {
  zxt.ui.TreeTemplate.call( this, sModel, sLabel, sText );
    
  sModel.addListener(this);
  
  this._status = 0; //0-current, 1-selected
  this._current = null;  
  this._selected = new Object();  

  this.hideRoot = false;
  this.emptyNodeAsLeaf = false;
  this.activeEmptyJudger = false;  
  this.nodeInitializer = null;

  this._rootNode = new zxt.ui.TreeNode(this, null, null, this._text, false, null);
  this._rootNode.active(false);
  
  this._target = this._rootNode;  
  this._jTreeDiv = $("<div/>");  
};

/**
 * <p>根据传入的DOM元素, 解析传入的相关属性, 创建相应的树控件</p>
 *
 * @function
 * @static
 * @param {DOM} elem 解析的DOM元素
 * @return {ZxtModeGrid} 根据传入的DOM元素创建的树控件
 */
zxt.ui.Tree.parse = function(elem){
	var j = $(elem);
	
	var tLabel = j.attr("zxt.label") || "LABEL";
	var tText = j.attr("zxt.text") || "TEXT";
	
	var _modelStr = j.attr("zxt.model");
	var _model = window[_modelStr];
	return new zxt.ui.Tree(_model, tLabel, tText);
};

zxt.defineClazz(zxt.ui.Tree, zxt.ui.TreeTemplate);

/**
 * <p>渲染函数</p>
 *
 * @function
 * @return {DOM} 渲染成的DOM节点
 */
zxt.ui.Tree.prototype.renderSelf = function(){
  this._jTreeDiv.empty(); 
  this._target.needRender(true); 	
  var rootDom = this._target.render();
  if( this.hideRoot ){
  	this._rootNode.expand();
  	this._jTreeDiv.append( this._target._jTreeChildrenDiv );
  }else{    
    this._jTreeDiv.append( rootDom );	
  }
  return this._jTreeDiv.get(0);
};

/**
 * @private
 */
zxt.ui.Tree.prototype.target = function(t){
  if (t === undefined) { return this._target;	}
  this._target = t;
};

/**
 * @private
 */
zxt.ui.Tree.prototype.forward = function(lb){ 
  var t = this._rootNode.getChildNode(lb);
  if( t != null ){
  	this._target = t;
  	this.render();
  }
};	

/**
 * @private
 */
zxt.ui.Tree.prototype.backward = function(){
  var p = this._target.parent();
  if ( p!=null ){
  	this._target = p;
  	this.render();
  }	
};

/**
 * @private
 */
zxt.ui.Tree.prototype.status = function(v){
  if (v === undefined) {	return this._status;	}
  this._status = v;
};

/**
 * <p>重新加载整个树, 如果传入了数据源, 会加载新的数据源, 否则重新加载源数据源</p>
 * 
 * @function
 * @param {zxt.data.TreeModel} [m] 树模型 
 */
zxt.ui.Tree.prototype.reload = function(m){
  this._model = m || this._model;
  this._rootNode.reload();
};

/**
 * <p>获取根节点</p>
 *　
 * @function
 * @returns {zxt.ui.TreeNode} 根节点
 */
zxt.ui.Tree.prototype.rootNode = function(){
  return this._rootNode;
};

/**
 * <p>打开树的根节点</p>
 *　
 * @function
 */
zxt.ui.Tree.prototype.expand = function(){
  this._rootNode.expand();
};

/**
 * <p>收缩树的根节点</p>
 *　
 * @function
 */
zxt.ui.Tree.prototype.collapse = function(){
  this._rootNode.collapse();
};

/**
 * <p>递归指定节点的父节点</p>
 *　
 * @function
 * @param {string} lb 节点的标签
 * @return {zxt.ui.TTNode} 树节点对象
 */
zxt.ui.Tree.prototype.expandNode = function(lb){
  var _n = this.getNode(lb);
  var _t = _n;
  while ( _t != null ){
	  _t.expand();
	  _t = _t.parent();
  }
  return _n;  
};

/**
 * <p>获取指定标签的子节点</p>
 *　
 * @function
 * @param {string} lb 节点的标签
 * @return {zxt.ui.TTNode} 树节点对象
 */
zxt.ui.Tree.prototype.getChildNode = function(lb){
  return this._rootNode.getChildNode(lb);
};

/**
 * 获取所有子节点
 *　
 * @function
 * @return {zxt.ui.TTNode[]} 所有子节点
 */
zxt.ui.Tree.prototype.getChildNodes = function(){
  return this._rootNode.getChildNodes();
};

/**
 * <p>设置当前节点</p>
 * @function
 * @param {zxt.ui.TreeNode} node 当前节点
 */
zxt.ui.Tree.prototype.setCurrent = function(node){  
  for( var k in this._selected ){
    this._selected[k]._jNodeTextDiv.removeClass("ef-tree-item-current");
  }
  this._selected = new Object();
  if ( this._current != null ){
    this._current._jNodeTextDiv.removeClass("ef-tree-item-current");
  }
  if ( node._jNodeTextDiv != null){
    node._jNodeTextDiv.addClass("ef-tree-item-current");
  }
  this._current = node;
};

/**
 * <p>返回当前节点</p>
 * @function
 * @returns {zxt.ui.TreeNode} 当前节点
 */
zxt.ui.Tree.prototype.getCurrent = function(){
  return this._current;
};

/**
 * @private
 */
zxt.ui.Tree.prototype._setSelected = function(node){  
  if ( this._current != null && (this._current.label()==node.label()) ){
	  alert("return");
	  return;
  }
  var _lb = node.label();
  if ( this._selected[_lb] ){	
    node._jNodeTextDiv.removeClass("ef-tree-item-current");
    delete this._selected[_lb];    
  } else {
    this._selected[_lb] = node;
    node._jNodeTextDiv.addClass("ef-tree-item-current");
  }
};

/**
 * <p>返回选中节点<>
 * @function
 * @returns {zxt.ui.TreeNode[]} 选中节点
 */
zxt.ui.Tree.prototype.getSeleted = function(){
  var ar = new Array();
  for( var k in this._selected ){
    ar.push(this._selected[k]);
  }
  return ar;
};

/**
 * <p>接收器</p>
 * @param {Event} e 事件
 * @param  {Object} param 参数
 * @return
 */
zxt.ui.Tree.prototype.accept = function(e, param){  
	if ( e === treeModelEvents.LOD ){
		this.reload();
	}
};

/**
 * <p>树模板节点</p>
 * @class  
 * @extends zxt.ui.TTNode
 * @param {zxt.ui.TreeTemplate} sTree 所属树控件
 * @param {zxt.ui.TTNode} sParent 父节点
 * @param {string} sLabel 节点标签
 * @param {string} sText 节点标题
 * @param {boolean} sLeaf 是否是节点点
 * @param {object} sData 节点相关数据
 */
zxt.ui.TreeNode = function( sTree, sParent, sLabel, sText, sLeaf, sData ) {
  this.base = zxt.ui.TTNode;
  this.base( sTree, sParent, sLabel, sText, sLeaf, sData );    

  this._jTreeNodeDIV = null;
  this._jBlankDiv = null;
  this._jNodeArchDiv = null;
  this._jNodeImgDiv = null;
  this._jTypeDiv = null;
  this._jNodeTextDiv = null;
  this._jTreeChildrenDiv = null;
  
  this._active = true;
  this._type = null;
  this._cIcon = null;
  this._oIcon = null;
  this._init = false;
  this._show = true;

  this._needRender = true;
  this._cascadeRender = false;  
};

zxt.defineClazz(zxt.ui.TreeNode, zxt.ui.TTNode);

/**
 * <p>初始化</p>
 * @private
 */
zxt.ui.TreeNode.prototype._initialize = function(){
  if ( this.leaf() ){
	 this._oIcon = zxt.ui.TreeConfig.fileIcon;
     this._cIcon = zxt.ui.TreeConfig.fileIcon;
  } else {
	 this._oIcon = zxt.ui.TreeConfig.openFolderIcon;
     this._cIcon = zxt.ui.TreeConfig.folderIcon;
  }  
  var _t = this.tree(); 
  var d = this.data();
  for( var key in d ){
    if ( typeof this[key] == "undefined" ){
      this[key] = d[key];
    }
  }
  if ( _t.nodeInitializer != null ){
    _t.nodeInitializer(this);//执行树节点构造方法，支持两种类型的树节点：CheckBox和Radio
  } 
  
  this._init = true;
};

/**
 * @private
 */
zxt.ui.TreeNode.prototype.show = function(v){
  if ( v === undefined ) {	return this._show;	}
  this._show = v;  
};

/**
 * <p>[GETTER|SETTER] 节点类型属性
 * 目前支持的节点类型属性有 多选框节点类型, 单选框框节点类型</p>
 * @function 
 * @param {zxt.ui.TreeItemType} v 参数
 * @return {zxt.ui.TreeItemType} 参数未定义，返回当前的类型设置
 */
zxt.ui.TreeNode.prototype.type = function(v){
  if ( v === undefined ) {	return this._type;	}
  this._type = v;
  if ( this._type != null ) {
    this._type.item = this;
  }
};

/**
 * <p>[GETTER|SETTER]激活状态
 * 激活树节点, 意味着树节点绑定了单击事件</p>
 *  
 * @function 
 * @param {boolean} v 参数
 * @return {boolean} 参数未定义，则返回当前的激活状态
 */
zxt.ui.TreeNode.prototype.active = function(v){
  if ( v === undefined ) {	return this._active;	}
  this._active = v;  
};

/**
 * <p>渲染状态</p>
 * @function
 * @param {boolean} v 参数
 * @return {boolean} 参数未定义，返回true
 */
zxt.ui.TreeNode.prototype.needRender = function(v){
  if ( v === undefined ) {	return true; }	
  if ( v === undefined ) {	return this._needRender; }
  this._needRender = v;
};

/**
 * <p>[GETTER|SETTER] 收缩状态下的图标</p> * 
 * @function 
 * @param {String} v 参数
 * @return {String} 参数未定义，返回当前的图标设置
 */
zxt.ui.TreeNode.prototype.icon = function(v){
  if ( v === undefined ) {	return this._cIcon;	}
  this._cIcon = v;
};

/**
 * <p>[GETTER|SETTER] 打开状态下的图标</p>
 * 
 * @function 
 * @param {String} v 参数
 * @return {String} 参数未定义，返回当前的图标设置
 */
zxt.ui.TreeNode.prototype.openIcon = function(v){
  if ( v === undefined ) {	return this._oIcon;	}
  this._oIcon = v;
};

/**
 * 打开节点
 * @function 
 */
zxt.ui.TreeNode.prototype.expand = function() {  
  this._needRender = this._opened?false:true;
  this._opened = true;
  this.load();
  this.render();
};

/**
 * <p>收缩节点</p>
 * @function 
 */
zxt.ui.TreeNode.prototype.collapse = function(){
  this._needRender = this._opened;
  this._opened = false;
  this.render();
};

/**
 * <p>判断当前节点是否有子节点</p>
 * @private
 * @function
 * @return {boolean} true:有 false：无
 */
zxt.ui.TreeNode.prototype._hasnext = function() {
	if( this.top() ){
		return false;
	}
    var parentItem = this._parent;
	var subItems = parentItem._childNodes;
	for( var k =0; k<subItems.length; k++ ){
		if( this == subItems[k] )	{
			if( k != subItems.length-1 ){
				return true;
			} else {
				return false;
			}
		}
	}
	return false;
};

/**
 * <p>[收缩|打开]图标的单击事件处理
 * 可以重设该函数来定制事件逻辑;</p>
 *
 * @function
 */
zxt.ui.TreeNode.prototype.onArchClicked = function( ){
  if ( this._opened ) {
    this.collapse();
  } else {
    this.expand();
  }
};

/**
 * <p>图标的单击事件处理
 * 可以重设该函数来定制事件逻辑;</p>
 *
 * @function 
 */
zxt.ui.TreeNode.prototype.onImageClicked = function( ){
  this.onArchClicked();
};

/**
 * <p>节点文本单击的回调
 * 可以重设该函数来定制事件逻辑;</p>
 *
 * @function
 */
zxt.ui.TreeNode.prototype.textClicked = function(){
};

/**
 * <p>节点文本的单击事件处理, 缺省会设置当前节点, 如果考虑保留缺省逻辑, 建议覆盖textClicked方法.</p>
 *
 * @function
 */
zxt.ui.TreeNode.prototype.onTextClicked = function( ){
  var tr = this.tree();
  switch( tr._status ){
    case 0:
		tr.setCurrent(this);
		this.textClicked();
		break;
	case 1:
		tr._setSelected(this);
		break;
  }  
};

/**
 * <p>节点文本右击的事件处理
 * 可以重设该函数来定制事件逻辑;</p>
 *
 * @function
 * @private
 */
zxt.ui.TreeNode.prototype.textContextMenu = function(){
};

/**
 * <p>节点文本单击的事件处理, 
 * 可以重设该函数来定制事件逻辑;</p>
 *
 * @function
 */
zxt.ui.TreeNode.prototype.onTextContextMenu = function( ){  
  this.textContextMenu(this);
};

/**
 * @private
 */
zxt.ui.TreeNode.prototype._createChildNode = function(child){
  var node = new zxt.ui.TreeNode( this.tree(), this, child['label'], child['text'], child['leaf']=="1", child );
  return node;
};

/**
 * <p>返回节点的DOM元素</p>
 *
 * @function
 * @returns {DOM} 节点的DOM元素
 */
zxt.ui.TreeNode.prototype.textDom = function(){
  return this._jNodeTextDiv.get(0);
};

/**
 * <p>重新加载</p>
 */
zxt.ui.TreeNode.prototype.reload = function(){
  this.load(true);
  this.needRender(true);
  this.render();
};

/**
 * <p>判断是否是叶子节点</p>
 * @return {boolean} true:是叶子节点 false:不是
 */
zxt.ui.TreeNode.prototype._asLeaf = function(){
  var renderAsLeaf = this._leaf;
  if (  !this._leaf ) {
    if ( this._status == 1 || this._opened){
	  if ( this.tree().emptyNodeAsLeaf && this.getChildNodes().length == 0 ) {
	    renderAsLeaf = true;
	  }
    } else if ( this.tree().activeEmptyJudger && this.getChildNodes().length == 0 ){
      renderAsLeaf = true;
    }
  }
  return renderAsLeaf;
};

/**
 * @private
 */
zxt.ui.TreeNode.prototype._renderSkeleton = function(){
  var tree = this.tree();
  if ( this._jTreeNodeDIV == null ) {
    this._jTreeNodeDIV = $("<div nowrap/>");
    this._jTreeNodeDIV.toggleClass( "ef-tree-item" );    
    this._jBlankDiv = $("<span/>");    
    this._jNodeArchDiv = $("<img/>");
    this._jNodeImgDiv = $("<img/>");     
    this._jNodeTextDiv = $("<a>").html( this._text );

    if ( !this._init ){
	  this._initialize();
    }
	
    if ( this._active ){
      this._jNodeTextDiv.attr("href", "javascript:void(0)");
    } 

    this._jTypeDiv = $("<span>");
    this._jTreeChildrenDiv = $("<div/>");
	this._jTreeNodeDIV.append(this._jBlankDiv).append( this._jNodeArchDiv ).append( this._jNodeImgDiv ).append(this._jTypeDiv).append( this._jNodeTextDiv ).append(this._jTreeChildrenDiv);

	var instance = this;
	this._jNodeArchDiv.click( function(){ instance.onArchClicked( ); });
	if ( this._active ){
      this._jNodeTextDiv.click( function(){ instance.onTextClicked();	});
	}	
	this._jNodeImgDiv.click( function(){ instance.onImageClicked();	});
    this._jNodeTextDiv.bind( "contextmenu", function(){ instance.onTextContextMenu(); return false;	});	
  }
};	

/**
 * @private
 */
zxt.ui.TreeNode.prototype._renderType = function(){
  this._jTypeDiv.empty();
  if ( this.type() != null ){
	  var typeDom = this.type().renderType();      
		this._jTypeDiv.append(typeDom);
  }
};

/**
 * @private
 */
zxt.ui.TreeNode.prototype._renderIndent = function(){
  var tree = this.tree();
  this._jBlankDiv.empty();
  var tmpItem = this;
  for(var j=this.depth(); j>tree._target.depth();j--){
	if( tmpItem._parent!=tree._target &&  tmpItem._parent._hasnext() ) {
	  this._jBlankDiv.prepend( $("<img/>").attr( "src", zxt.ui.TreeConfig.iIcon ) );
	} else {
	  this._jBlankDiv.prepend( $("<img/>").attr( "src", zxt.ui.TreeConfig.blankIcon ) );				
	}
    tmpItem = tmpItem._parent;
  }
};

/**
 * @private
 */
zxt.ui.TreeNode.prototype._renderChildren = function(opened){  	
  this._jTreeChildrenDiv.empty();  
  if (opened){
    var children = this.getChildNodes();
    for( var i=0; i<children.length; i++ ){
      var child = children[i];
      var cDom = child.render();
      if ( child._show ){
        this._jTreeChildrenDiv.append( cDom );
      }
    }
  }  
};

/**
 * @private
 */
zxt.ui.TreeNode.prototype._renderIconText = function(asLeaf){
  var closedIcon = this._cIcon;
  var openIcon = this._oIcon;
  
  this._jNodeTextDiv.html( this._text );	
  
  if ( asLeaf ){
    if ( this._hasnext() ) {
        this._jNodeArchDiv.attr( "src", zxt.ui.TreeConfig.tIcon );
	  } else {
	    this._jNodeArchDiv.attr( "src", zxt.ui.TreeConfig.lIcon );
      }
      this._jNodeImgDiv.attr("src", closedIcon );
  } else {
    if ( this._opened ) {
      if ( this._hasnext() ) {
        this._jNodeArchDiv.attr( "src", zxt.ui.TreeConfig.tMinusIcon );
	  } else {
	    this._jNodeArchDiv.attr( "src", zxt.ui.TreeConfig.lMinusIcon );
      }
      this._jNodeImgDiv.attr("src", openIcon );	  
    } else {
	  if ( this._hasnext() ) {
        this._jNodeArchDiv.attr( "src", zxt.ui.TreeConfig.tPlusIcon );
	  } else {
	    this._jNodeArchDiv.attr( "src", zxt.ui.TreeConfig.lPlusIcon );
      }
	  this._jNodeImgDiv.attr("src", closedIcon );      
    }    
  }
};	
	
/**
 * <p>渲染DOM节点</p>
 * @function
 */
zxt.ui.TreeNode.prototype.renderSelf = function(){    	
  this._renderSkeleton();  
  this._renderType();  //渲染节点类型，目前支持CheckBox和Radio两种

  if ( this.needRender() || this._cascadeRender ){
  	this.needRender(false);
	this._cascadeRender = false; 
  } else {     
    return this._jTreeNodeDIV.get(0);	 
  }
    
  this._renderIndent();   
  var asLeaf = this._asLeaf();
  this._renderIconText(asLeaf);
  if (!asLeaf){
  	this._renderChildren(this._opened);
  }  
  return this._jTreeNodeDIV.get(0);
};

/*  Tree Item Type */
/**
 * <p>树节点类型</p>
 * @class
 * 
 */
zxt.ui.TreeItemType = function(){
	this.item = null;
};	
	
/* check box type */
/**
 * <p>设置节点的CheckBox</p>
 * @function
 * @param {boolean} pChecked 勾选参数：true:勾选
 */
zxt.ui.CheckItemType = function(pChecked){
	this.checked = false;	
	if ( pChecked != null ){ this.checked = pChecked };	
	this._jqDom = null;
};

zxt.defineClazz(zxt.ui.CheckItemType, zxt.ui.TreeItemType);

/**
 * <p>渲染节点类型控件</p>
 * @function
 * @return {DOM} 节点DOM
 */
zxt.ui.CheckItemType.prototype.renderType = function (){
  var host = this; 
  var ck = "";
  if ( this.checked ) {
    ck = "checked";
  }
  var t = "<input type='checkbox' "+ ck +">";
  var check = $(t); 
  check.click( function(){ host.checkClicked(); } );
  this._jqDom = check;
  return check.get(0);
};

/**
 * <p>点击CheckBox控件的方法事件</p>
 * @param {Object} c 参数
 * @return
 */
zxt.ui.CheckItemType.prototype.checkClicked = function (c) {
  var bChecked = !this.checked;
  this.checkItem( bChecked );
};

/**
 * <p>点击CheckBox控件的方法事件</p>
 * @function
 * @private
 * @param {boolean} bChecked 是否检查参数
 * @return
 */
zxt.ui.CheckItemType.prototype.checkItem = function (bChecked) { 
  this.checked = bChecked;
  this.checkDom(bChecked);
  var node = this.item;
  if ( node.open() ) {
    for (var i = 0; i < node._childNodes.length; i++) {
	   var sub = node._childNodes[i];		   
	   if ( sub._type.instanceOf(zxt.ui.CheckItemType) ) {sub._type.checkItem(bChecked); }		    
	}
  }  
};

/**
 * @private
 * @param bChecked
 * @return
 */
zxt.ui.CheckItemType.prototype.checkDom = function (bChecked) {
     this.checked = bChecked;
	 this._jqDom.attr("checked", this.checked); 		  
};

/**
 * <p>获得所有的Checked孩子节点</p>
 * @return {Array} 所有的Checked孩子节点
 */
zxt.ui.Tree.prototype.getCheckedNods = function() {
	var _selectedItems	= [];	    
	   
	for (var i = 0; i < this._rootNode._childNodes.length; i++) {
    var node = this._rootNode._childNodes[i];
    var nodeType = node._type;
    if ( nodeType.instanceOf(zxt.ui.CheckItemType) && nodeType.checked )
    {
      _selectedItems[_selectedItems.length] = node;
    }
	_addSelectedItems(node, _selectedItems);		        
  }
	return _selectedItems;
};

/**
 * <p>获得所有checked节点的Label数组</p>
 * @return {Array} checked节点的Label数组
 */
zxt.ui.Tree.prototype.getChecked = function() {
    var _selected = [];
	var nodes = this.getCheckedNods();
	for( var i=0; i<nodes.length;i++ ){
	   _selected[_selected.length] = nodes[i].label();
	}
	return _selected;
};

/**
 * <p>获得当前节点的所有的Checked孩子节点</p>
 * @private
 */
function _addSelectedItems(item, _selectedItems) {	    
	for (var i = 0; i < item._childNodes.length; i++) {
		var sub = item._childNodes[i];	
		var subType = sub._type;	   
		if ( subType.instanceOf(zxt.ui.CheckItemType) && subType.checked ) {
			_selectedItems[_selectedItems.length] = sub;
		}
		_addSelectedItems(sub, _selectedItems);
	}
};

/* radiobox tree item type */
/**
 *<p>设置节点的Radio</p> 
 *@param {boolean} pChecked 标识是否选中
 */
zxt.ui.RadioItemType = function(pChecked){
	this.checked = false;
	if ( pChecked != null ){ this.checked = pChecked };	
	this._jqDom = null;
};

zxt.defineClazz(zxt.ui.RadioItemType, zxt.ui.TreeItemType);

/**
 * <p>渲染节点类型控件</p>
 * @function
 * @return {DOM} 节点DOM
 */
zxt.ui.RadioItemType.prototype.renderType = function () {
  var host = this;
  var ck = "";
  if ( this.checked ) {
    ck = "checked";
  }
  var t = "<input type='radio' "+ ck +">";
  var check = $(t);
  check.click( function(){ host.radioClicked(); } );	
  this._jqDom = check;
  return check.get(0);
};

/**
 * <p>点击Radio控件的方法事件</p> 
 * @return
 */
zxt.ui.RadioItemType.prototype.radioClicked = function () {
  var bChecked = !this.checked;
  this.checkItem( bChecked );
};

/**
 * <p>点击Radio控件的方法事件</p>
 * @function
 * @private
 * @param {boolean} bChecked 是否检查参数
 * @return
 */
zxt.ui.RadioItemType.prototype.checkItem = function (bChecked) {
	var tree = this.item.tree();
	if ( tree.option && tree.option._label == this.item._label ){
		this.checkDom(false);
		tree.option = null;
	} else {
		if ( tree.option ){	tree.option._type.checkDom( false ) };
		this.checkDom(true);
		tree.option = this.item;
	}
};

/**
 * @private
 * @param bChecked
 * @return
 */
zxt.ui.RadioItemType.prototype.checkDom = function (bChecked) {
	this.checked = bChecked;					
	this._jqDom.attr("checked", this.checked);  
};

/**
 * <p>获得选择的标签</p>
 * @function
 * @return {String} 没有选择，返回空；否则，返回选择的标签
 */
zxt.ui.Tree.prototype.getOption = function() {
	if (this.option == null){return ""};
	return this.option._label;
};






